//
//  HotelViewController.swift
//  驻外机组
//
//  Created by apple on 16/4/19.
//  Copyright © 2016年 com.csair. All rights reserved.
//

import UIKit

class HotelViewController: UIViewController,UIScrollViewDelegate {

    @IBOutlet weak var imagescrollview: UIScrollView!
    @IBOutlet weak var imagepagecontrol: UIPageControl!
    var bigImage:UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        imagescrollview.delegate = self
        imagepagecontrol.numberOfPages = 3
        var height = imagescrollview.bounds.height
        var width = UIScreen.mainScreen().bounds.width
        for i in 0...2 {
            
            let iv = UIImageView(frame: CGRectMake(width * CGFloat(i), 0, width, height))
            iv.image = UIImage(named: "广州\(i+1)")
            iv.contentMode = UIViewContentMode.ScaleToFill
            iv.clipsToBounds = true
            iv.userInteractionEnabled = true
            var tap = UITapGestureRecognizer(target:self, action: Selector("ShowFullScreenImageView:"))
            iv.addGestureRecognizer(tap)
            imagescrollview.addSubview(iv)
        }
        
        imagescrollview.contentSize = CGSizeMake(width * 3, height)
    }
    
    func ShowFullScreenImageView(utgr:UITapGestureRecognizer)
    {
        let currentPage = imagescrollview.contentOffset.x / UIScreen.mainScreen().bounds.width + 0.5
        bigImage = UIImageView (frame: UIScreen.mainScreen().bounds)
        bigImage.backgroundColor = UIColor.blackColor()
        bigImage.contentMode = UIViewContentMode.ScaleAspectFit
        bigImage.image = UIImage(named: "广州\(currentPage+1)")
        bigImage.frame = UIScreen.mainScreen().applicationFrame
        self.navigationController?.setNavigationBarHidden(true, animated: false)
        self.view.addSubview(bigImage)
        bigImage.userInteractionEnabled = true
        var tap = UITapGestureRecognizer(target:self, action: Selector("HideFullScreenImageView:"))
        bigImage.addGestureRecognizer(tap)
    }
    
    func HideFullScreenImageView(utgr:UITapGestureRecognizer)
    {
        bigImage.removeFromSuperview()
        self.navigationController?.setNavigationBarHidden(false, animated: false)
        
    }
    
    func scrollViewDidScroll(scrollView: UIScrollView) {
        if scrollView == self.imagescrollview{
            let currentPage = scrollView.contentOffset.x / UIScreen.mainScreen().bounds.width + 0.5
            imagepagecontrol.currentPage = Int(currentPage)
        }
    }
    //循环轮播的时候使用 暂时不用这个功能
//    func scrollViewDidZoom(scrollView: UIScrollView) {
//        if scrollView == self.imagescrollview {
//            let width = UIScreen.mainScreen().bounds.width
//            let offsetX = scrollView.contentOffset.x
//            
//            if offsetX == 0 {
//                scrollView.contentOffset = CGPointMake(width * CGFloat(4), 0)
//            }
//            if offsetX == width * CGFloat(4 + 1) {
//                scrollView.contentOffset = CGPointMake(width, 0)
//            }
//            
//            let currentPage = scrollView.contentOffset.x / width - 0.5
//            self.imagepagecontrol.currentPage = Int(currentPage)
//        }
//    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
